'on my system malloc is 2x faster than array in release. memclear esp helps



SuperStrict

Global width% = 800
Global height% = 600
Global siz% = width*height

'alloc
'iterate
'clear

Global bytes% = 4*siz
Global mdata:Float Ptr = Float Ptr( MemAlloc(bytes) )
Global adata:Float[] = New Float[siz]

Local tim1:Int = MilliSecs()
rawbench()
Local tim2:Int = MilliSecs()
arraybench()
Local tim3:Int = MilliSecs()

Print "raw/malloc: "+(tim2-tim1)
Print "array:      "+(tim3-tim1)

Function rawbench()
	
	
	
	For Local i%=0 Until width
	For Local j%=0 Until height
		Local idx% = i*height+j
		mdata[idx] = i*j
		'Print idx+" "+ 
	Next
	Next
	
	MemClear(mdata,bytes)
	'For Local i:Int = 0 Until siz
	'	mdata[i]  = 0
	'Next
End Function

Function arraybench()
	
	
	For Local i%=0 Until width
	For Local j%=0 Until height
		Local idx% = i*height+j
		adata[idx] = i*j
		'Print idx+" "+ 
	Next
	Next
	
	For Local i:Int = 0 Until siz
		adata[i]  = 0
	Next
End Function
